Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First attempt at supporting https connections through proxy #186

Merged
merged 1 commit into from
Apr 4, 2015

Conversation

Connorhd
Copy link
Contributor

This is pretty rough but I wanted to see if this looks like I'm at all going in the right direction. I added a failing test which now passes, so I think this is at least functional. Any feedback on what I need to do to get this into a mergable state would be great.

Connecting to https servers through a http proxy requires sending a CONNECT request to the proxy to setup a tunnel, then performing a normal https request through that tunnel. This PR adds the code to send that CONNECT request before continuing with the normal request.

# Adds headers to be sent to the proxy
def add_proxy_connect_headers
@headers.each do |field, value|
next unless ['Host', 'User-Agent'].include? field
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to move this array into a constant and make it a set:

PROXY_HEADERS_WHITELIST = %w(Host User-Agent).to_set.freeze

@sferik sferik modified the milestone: v0.8.0 Mar 28, 2015
@Connorhd Connorhd force-pushed the https-through-proxy-support branch 5 times, most recently from f78df33 to fa64bdb Compare March 29, 2015 02:34
@ixti ixti assigned ixti and unassigned ixti Mar 29, 2015
@ixti ixti modified the milestones: v0.9, v0.8 Apr 1, 2015
@ixti ixti removed their assignment Apr 1, 2015
@ixti
Copy link
Member

ixti commented Apr 1, 2015

@Connorhd I have rebased and cleaned up a bit your PR. By some reason 3 examples are failing with "IOError: problem making HTTP request: end of file reached" now. Please, see branch:
feature/https-through-proxy-support.

/cc @zanker

@Connorhd Connorhd force-pushed the https-through-proxy-support branch from fa64bdb to 031fc01 Compare April 4, 2015 00:58
@Connorhd
Copy link
Contributor Author

Connorhd commented Apr 4, 2015

@ixti I've fixed the tests on your rebase, one of the condition changes got lost in the rebase, plus the ssl tests need the ssl client to be configured now.

@tarcieri
Copy link
Member

tarcieri commented Apr 4, 2015

👍 from me

@connection.send_request(req)
@connection.read_headers!

unless @connection.failed_proxy_connect?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A failed proxy connection should be an error, rather than soft failing I think. It's the equivalent of a socket error in that you're saying to connect to X and it failed.

If the concern is around accessing the response for further debugging, we can do something like what Net::HTTP does and include response as part of the error.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's unclear to me what the correct behavior is here. This case includes the 407 response when proxy authentication fails (which we have a test case for), its also consistent with the current behavior for http proxies.

i.e.
HTTP.get('http://not-real-sldjflkdjlkds.com') => exception
HTTP.via(proxy.addr, proxy.port).get('http://not-real-sldjflkdjlkds.com') => 500 response

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okie-doke. If it's consistent with what we have then 👍

@zanker
Copy link
Contributor

zanker commented Apr 4, 2015

Besides that looks good to me. If you could fix those two things can merge. Thanks for working through this!

@Connorhd Connorhd force-pushed the https-through-proxy-support branch from 031fc01 to 4bfa1ee Compare April 4, 2015 16:55
@Connorhd Connorhd force-pushed the https-through-proxy-support branch from 4bfa1ee to 6aed65f Compare April 4, 2015 16:58
@Connorhd
Copy link
Contributor Author

Connorhd commented Apr 4, 2015

@zanker Updated with those changes

ixti added a commit that referenced this pull request Apr 4, 2015
First attempt at supporting https connections through proxy
@ixti ixti merged commit 89dbe73 into httprb:master Apr 4, 2015
@ixti
Copy link
Member

ixti commented Apr 4, 2015

Awesome! Thanks!

ixti added a commit that referenced this pull request Apr 6, 2015
zanker pushed a commit to zanker/http.rb that referenced this pull request May 8, 2015
@timrwilliams
Copy link

Hi guys, trying to test this out in irb using version 0.8.5 and it hangs whenever I try and access an HTTPS endpoint.

HTTP.via("176.31.170.159", 8080).get("https://www.google.com/")

Has anybody got this working against a real proxy server? It works fine from curl on the command line.

curl --proxy http://176.31.170.159:8080 -k https://www.google.co.uk/

(Sample HTTP proxies taken from http://proxylist.hidemyass.com/search-1297445#listable)

@ixti
Copy link
Member

ixti commented May 8, 2015

Thanks for report! I confirm bug exists.

@ixti ixti mentioned this pull request May 8, 2015
@ixti
Copy link
Member

ixti commented May 9, 2015

@timrwilliams Fixed in master. Will cut new release today or tomorrow.

@timrwilliams
Copy link

Nice, I've tested master and it works like a charm now. We've got an issue over on the Twitter gem (sferik/twitter-ruby#663) that needs this so cutting a new release would be really helpful.

@ixti
Copy link
Member

ixti commented May 9, 2015

@timrwilliams OK.

@ixti
Copy link
Member

ixti commented May 9, 2015

@timrwilliams Released as 0.8.8

@ixti ixti modified the milestones: v0.10, v0.9 Jul 22, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants